<template>
  <div class="container">
    <div class="left">
      <div class="title">
        <img src="@/assets/icon/tag.png" alt="" />
        <h2>{{ $route.query.name }}</h2>
      </div>
      <div class="box">
        <div class="item" v-for="(item, index) in tableData" :key="index">
          <p class="item_img">
            <img :src="item.titleImage" alt="" />
          </p>
          <div class="item_content">
            <h3>{{ item.title }}</h3>
            <p>{{ item.description }}</p>
            <p>
              <span
                v-for="(item, index) in item.tags"
                :key="index"
                @click="toIncludeTag(item)"
                >{{ item.name }}</span
              >
            </p>
          </div>
        </div>
      </div>
      <div class="page">
        <Page-com
          :pages="pages"
          :pageSize="pageSize"
          :pageNumber="pageNumber"
          @back="currentIndex"
        ></Page-com>
      </div>
    </div>
    <div class="right">
      <div class="right_1">
        <Ha-com></Ha-com>
      </div>
      <div class="right_2">
        <Type-com></Type-com>
      </div>
    </div>
  </div>
</template>

<script>
import PageCom from "@/components/PageCom.vue";
import HaCom from "@/components/HaCom.vue";
import TypeCom from "@/components/TypeCom.vue";

export default {
  data() {
    return {
      tableData: "",
      title: "",
      //组件传参
      pages: [],
      pageSize: 10,
      pageNumber: null,
      currentInd: 1,
    };
  },
  components: {
    PageCom,
    HaCom,
    TypeCom,
  },
  methods: {
    toIncludeTag(item) {
      this.$router.push({
        path: "/home/includetag",
        query: item,
      },()=>{},()=>{});
    },
    //当前点击的页码
    currentIndex(val) {
      console.log(val);
    },
    getData() {
      this.$axios
        .post("api/tag/article/list", {
          tagId: Number(this.$route.query.id) ,
          current: 1,
          size: 10,
        })
        .then((res) => {
          this.tableData = res.data;
          for (let i = 0; i < res.pages; i++) {
            this.pages.push(i + 1);
          }
        });
    },
  },
  created() {
    console.log(this.$route.query, "query");
    this.getData();
  },
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: space-around;
  .left {
    width: 960px;
    .title {
      display: flex;
      flex-direction: row;
      img {
        width: 30px;
      }
    }
    .box {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-between;
      .item {
        width: 444px;
        height: 300px;
        border-radius: 20px;
        border: #ddd solid 1px;
        margin-bottom: 10px;
        background-color: #fff;
        .item_img {
          img {
            width: 444px;
            height: 200px;
            vertical-align: middle;
            border-radius: 10px 10px 0px 0px;
          }
        }
        .item_content {
          padding: 10px;
          width: 100%;
          height: calc(100% - 200px);
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          text-align: left;
          box-sizing: border-box;

          border-radius: 0px 0px 10px 10px;
          span {
            background-color: rgb(182, 248, 182);
            margin-right: 5px;
            padding: 2px 5px 2px 5px;
            border-radius: 2px;
            font-size: 10px;
          }
          span:hover {
            background-color: rgb(125, 255, 125);
          }
        }
      }
    }
  }
  .right {
    width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .right_1 {
      padding: 10px;
      background-color: #fff;
      width: 80%;
      height: 200px;
      border: #ddd solid 1px;
      border-radius: 10px;
    }
    .right_2 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
    .right_3 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
  }
}
</style>